home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / exec / enqueue.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  3KB  |  117 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: enqueue.c,v 1.7 1996/10/24 15:50:48 aros Exp $
  4.     $Log: enqueue.c,v $
  5.     Revision 1.7  1996/10/24 15:50:48  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.6  1996/10/21 20:47:07  aros
  9.     Changed struct SysBase to struct ExecBase
  10.  
  11.     Revision 1.5  1996/08/13 13:56:01  digulla
  12.     Replaced AROS_LA by AROS_LHA
  13.     Replaced some AROS_LH*I by AROS_LH*
  14.     Sorted and added includes
  15.  
  16.     Revision 1.4  1996/08/01 17:41:10  digulla
  17.     Added standard header for all files
  18.  
  19.     Desc:
  20.     Lang: english
  21. */
  22. /* I want the macros */
  23. #define AROS_ALMOST_COMPATIBLE
  24. #include "exec_intern.h"
  25.  
  26. /*****************************************************************************
  27.  
  28.     NAME */
  29.     #include <exec/lists.h>
  30.     #include <clib/exec_protos.h>
  31.  
  32.     AROS_LH2I(void, Enqueue,
  33.  
  34. /*  SYNOPSIS */
  35.     AROS_LHA(struct List *, list, A0),
  36.     AROS_LHA(struct Node *, node, A1),
  37.  
  38. /*  LOCATION */
  39.     struct ExecBase *, SysBase, 45, Exec)
  40.  
  41. /*  FUNCTION
  42.     Sort a node into a list. The sort-key the field node->ln_Pri.
  43.  
  44.     INPUTS
  45.     list - Insert into this list. The list has to be in descending
  46.         order in respect to the field ln_Pri of all nodes.
  47.     node - This node is to be inserted. Note that this has to
  48.         be a complete node and not a MinNode !
  49.  
  50.     RESULT
  51.  
  52.     NOTES
  53.     The list has to be in descending order in respect to the field
  54.     ln_Pri of all nodes.
  55.  
  56.     EXAMPLE
  57.     struct List * list;
  58.     struct Node * node;
  59.  
  60.     // Sort the node at the correct place into the list
  61.     Enqueue (list, node);
  62.  
  63.     BUGS
  64.  
  65.     SEE ALSO
  66.  
  67.     INTERNALS
  68.  
  69.     HISTORY
  70.     26-08-95    digulla created after EXEC-Routine
  71.     26-10-95    digulla adjusted to new calling scheme
  72.  
  73. ******************************************************************************/
  74. {
  75.     AROS_LIBFUNC_INIT
  76.     struct Node * next;
  77.  
  78.     assert (list);
  79.     assert (node);
  80.  
  81.     /* Look through the list */
  82.     for (next=GetHead(list); next; next=GetSucc(next))
  83.     {
  84.     /*
  85.         if the NEXT node has lower prio than the new node, insert us
  86.         before the next node
  87.     */
  88.     if (node->ln_Pri >= next->ln_Pri)
  89.     {
  90.         /* Same as insert but insert before instead of insert behind */
  91.         node->ln_Succ = next;
  92.         node->ln_Pred = next->ln_Pred;
  93.  
  94.         next->ln_Pred->ln_Succ = node;
  95.         next->ln_Pred       = node;
  96.  
  97.         /*
  98.         Done. We cannot simly break the loop because of the AddTail()
  99.         below.
  100.         */
  101.         return;
  102.     }
  103.     }
  104.  
  105.     /*
  106.     If no nodes were in the list or our node has the lowest prio,
  107.     we add it as last node
  108.     */
  109.     node->ln_Succ           = (struct Node *)&list->lh_Tail;
  110.     node->ln_Pred           = list->lh_TailPred;
  111.  
  112.     list->lh_TailPred->ln_Succ = node;
  113.     list->lh_TailPred           = node;
  114.     AROS_LIBFUNC_EXIT
  115. } /* Enqueue */
  116.  
  117.